package pingan.com.quarter_hour.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import pingan.com.quarter_hour.R;
import pingan.com.quarter_hour.adpater.ZCrossTalkAdapter;
import pingan.com.quarter_hour.bean.ZDuanziItem;
import pingan.com.quarter_hour.view.IView;
import pingan.com.quarter_hour.z_presenter.CrossTalkPresenter;

/**
 * Created by 迷人的脚毛！！ on 2018/1/9.
 */

public class EpisodeFragment extends Fragment implements IView {

    private View view;
    private RecyclerView crossTalkItems;
    List<ZDuanziItem.DataBean> list=new ArrayList<>();
    private CrossTalkPresenter talkPresenter;
    private String str;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.episode_fragment, container, false);

        crossTalkItems= view.findViewById(R.id.cross_talk_items);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
        crossTalkItems.setLayoutManager(linearLayoutManager);
        ZCrossTalkAdapter zCrossTalkAdapter = new ZCrossTalkAdapter(getActivity(),list);
        crossTalkItems.setAdapter(zCrossTalkAdapter);

        talkPresenter = new CrossTalkPresenter();
        talkPresenter.attachview(this);
        HashMap<String,String> map=new HashMap<>();
        map.put("page","1");
        //https://www.zhaoapi.cn/quarter/getJokes?page=1&token=1&source=android&appVersion=101
        talkPresenter.getCrossTake("https://www.zhaoapi.cn/",map);
        return view;

    }


    @Override
    public void success(Object o) {
        ZDuanziItem news= (ZDuanziItem) o;
        if (news!=null){
            List<ZDuanziItem.DataBean> data = news.getData();
            list.addAll(data);
            ZCrossTalkAdapter zCrossTalkAdapter = new ZCrossTalkAdapter(getActivity(),list);
            crossTalkItems.setAdapter(zCrossTalkAdapter);
            zCrossTalkAdapter.notifyDataSetChanged();
        }

    }

    @Override
    public void Failes(Exception e) {
    }
}

